<#assign module="driver"/>

<@override name="header">
    <link rel="stylesheet" href="${ctx}/assets/css/datetimepicker.css">
    <link rel="stylesheet" href="${ctx}/assets/css/bootstrap-multiselect.css">
    <style>
        .removedriver {
            cursor: pointer
        }
    </style>
</@override>
<@override name="body">
    <div class="tabbable tabs-left">
        <div class="row">
            <div class="col-xs-12 col-md-10">
                <div class="orders-navt">
                    <ul class="orders-nav">
                        <@shiro.hasPermission name='servicePersonal'>
                            <li style="width:90px;"><a href="${ctx}/driver/list">服务人员</a></li>
                        </@shiro.hasPermission>

                        <@shiro.hasPermission name='drivergrade'>
                            <li style="width:110px;"><a href="${ctx}/drivergrade/list">服务人员等级</a></li>
                        </@shiro.hasPermission>
                        <@shiro.hasPermission name='driverapply'>
                            <li><a href="${ctx}/driverapply/list">申请</a></li>
                        </@shiro.hasPermission>
                        <@shiro.hasPermission name='callLog'>
                            <li style="width:90px;"><a href="${ctx}/driver/recordlist">通话记录</a></li>
                        </@shiro.hasPermission>
                        <@shiro.hasPermission name='notice'>
                            <li><a href="${ctx}/notice/list">通知</a></li>
                        </@shiro.hasPermission>
                        <@shiro.hasPermission name='announcement'>
                            <li style="width:90px;"><a href="${ctx}/driver/announcementList">公告</a></li>
                        </@shiro.hasPermission>
                        <@shiro.hasPermission name='drivermoney' >
                            <li style="width:90px;" class="orders-click"><a href="${ctx}/driver/drivermoney">批量操作</a>
                            </li>
                        </@shiro.hasPermission>
                        <@shiro.hasPermission name='drivermoney'>
                            <li style="width:110px;"><a href="${ctx}/driver/driverReward">服务人员奖励</a></li>
                        </@shiro.hasPermission>
                        <@shiro.hasPermission name='driverenchashment'>
                            <li style="width:100px;"><a href="${ctx}/driverenchashment/list">申请提现</a></li>
                            <li style="width:120px;"><a href="${ctx}/driverRebateenchashment/extendList">申请提取推广奖励</a></li>
                        </@shiro.hasPermission>
                        <@shiro.hasPermission name='driverloginrecord'>
                            <li style="width:90px;"><a href="${ctx}/driver/loginlist">登录日志</a></li>
                        </@shiro.hasPermission>
                    </ul>
                </div>
            </div>
        </div>
    </div>
    <div class="tab-content">
        <div class="container-fluid margin-top">
            <div class="row">
                <div class="col-md-12">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            批量充值
                        </div>
                        <div class="panel-body">
                            <form id="submit_form" action="${ctx}/driver/driverMoney" class="form-horizontal"
                                  method="post">
                                <div class="form-group">
                                    <label class="col-sm-2 control-label"><em>*</em>单个金额：</label>
                                    <div class="col-sm-4">
                                        <input class="form-control" type="number" id="money" name="money"/>
                                    </div>
                                    <span style="color:red">正数表示充值,负数表示扣费。0元不生成记录</span>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label"><em>*</em>充值说明：</label>
                                    <div class="col-sm-4">
                                        <textarea class="form-control" id="memo" name="memo" rows="8"></textarea>
                                    </div>
                                    <span style="color:red">输入本次充值或扣费的文字说明</span>
                                </div>
                                <h4>筛选条件<font color="red">（默认为所有服务人员）</font></h4>

                                <div class="form-group">
                                    <label class="col-sm-2 control-label">姓名：</label>
                                    <div class="col-sm-2">
                                        <input class="form-control" type="text" id="name" name="name"/>
                                    </div>

                                    <label class="col-sm-1 control-label">电话：</label>
                                    <div class="col-sm-3">
                                        <input class="form-control" type="text" id="phone" name="phone"/>
                                    </div>

                                    <label class="col-sm-1 control-label">工号：</label>
                                    <div class="col-sm-2">
                                        <input class="form-control" type="text" id="username" name="username"/>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">余额少于：</label>
                                    <div class="col-sm-2">
                                        <input class="form-control" type="text" id="virtual" name="virtual"/>
                                    </div>
                                    <label class="col-sm-1 control-label">入职时间：</label>
                                    <div class="col-sm-3">
                                        <div class="input-group">
                                            <input type="text" class="form-control" id="startTime" name="startTime">
                                            <span class="input-group-addon">到</span>
                                            <input type="text" class="form-control" id="endTime" name="endTime">
                                        </div>
                                    </div>
                                    <@shiro.isMainCompany>
                                        <label class="col-sm-1 control-label">所属公司：</label>
                                        <div class="col-sm-3">
                                            <input type="hidden" id="companyName" name="companyName" value=""/>
                                            <select class="form-control" id="companyId" name="companyId"
                                                    multiple="multiple">
                                                <#list companys as company>
                                                    <option value="${company.id}">${company.abbreviation}</option>
                                                </#list>
                                            </select>
                                        </div>
                                    </@shiro.isMainCompany>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">类型：</label>
                                    <div class="col-sm-10">
                                        <p class="form-control-static">
                                            <label style="padding-right:12px;">
                                                <input type="checkbox" name="type" value="兼职"/> 兼职
                                            </label>
                                            <label style="padding-right:12px;">
                                                <input type="checkbox" name="type" value="全职"/> 全职
                                            </label>
                                        </p>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">服务类型：</label>
                                    <div class="col-sm-10">
                                        <p class="form-control-static">
                                            <@daijia>
                                                <label style="padding-right:12px;">
                                                    <input type="checkbox" name="jobType" value="daijia"/> 代驾
                                                </label>
                                            </@daijia>
                                            <@zhuan>
                                                <label style="padding-right:12px;">
                                                    <input type="checkbox" name="jobType" value="zhuanche"/> 专车
                                                </label>
                                            </@zhuan>
                                            <@pao>
                                                <label style="padding-right:12px;">
                                                    <input type="checkbox" name="jobType" value="paotui"/> 跑腿
                                                </label>
                                            </@pao>
                                            <@freight>
                                                <label style="padding-right:12px;">
                                                    <input type="checkbox" name="jobType" value="freight"/> 货运
                                                </label>
                                            </@freight>
                                        </p>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">状态：</label>
                                    <div class="col-sm-10">
                                        <p class="form-control-static">
                                            <label style="padding-right:12px;">
                                                <input type="checkbox" name="status" value="1"/> 上线
                                            </label>
                                            <label style="padding-right:12px;">
                                                <input type="checkbox" name="status" value="2"/> 接单
                                            </label>
                                            <label style="padding-right:12px;">
                                                <input type="checkbox" name="status" value="3"/> 忙碌
                                            </label>
                                            <label style="padding-right:12px;">
                                                <input type="checkbox" name="status" value="0"/> 未上线
                                            </label>
                                            <label style="padding-right:12px;">
                                                <input type="checkbox" name="freeze" value="freeze"/> 冻结
                                            </label>
                                        </p>
                                    </div>
                                </div>

                                <div class="form-group" style="margin-left:10px;">
                                    <label class="col-sm-3 control-label"></label>
                                    <input id="submit_button" type="button" class="btn btn-primary" value="确认">
                                    <input type="button" class="btn btn-default"
                                           onclick="window.location.href = '${ctx}/driver/list';" value="返回">
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!--筛选详情-->
    <div class="form-horizontal">
        <div class="modal fade" id="dialog_driver" data-backdrop="static">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="false">&times;</button>
                        <h4 class="modal-title">筛选详情</h4>
                    </div>
                    <div class="modal-body">
                        <form action="" method="post">
                            <div id="driver_btn" class="row" style="margin-left:10px;">
                            </div>
                            <div class="form-group" style="margin-left:40px;margin-top:30px;">
                                <div class="col-sm-4">
                                </div>
                                <div class="col-sm-8">
                                    <span>已筛选出</span>&emsp;<input type="text" style="width:30px;border:none;color:red;"
                                                                  id="number" readonly/><span>位服务人员</span>
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="col-sm-5">
                                </div>
                                <div class="col-sm-7">
                                    <input type="button" class="btn btn-primary" id="save" value="确定">
                                    <button type="button" class="btn btn-default" id="cancel">关闭</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</@override>

<@override name="footer">
    <script src="${ctx}/assets/js/bootstrap-multiselect.js"></script>
    <script src="${ctx}/assets/js/datepicker.js"></script>
    <script type="text/javascript">
        var save_submit = false;
        $(document).ready(function () {
            $("#startTime").val("");
            $("#endTime").val("");

            $("#startTime").datetimepicker({
                format: 'yyyy-mm-dd',
                language: 'zh-CN',
                minView: 'month',
                pickDate: true,
                pickTime: false,
                inputMask: false,
                autoclose: true
            });
            $("#endTime").datetimepicker({
                format: 'yyyy-mm-dd',
                language: 'zh-CN',
                minView: 'month',
                pickDate: true,
                pickTime: false,
                inputMask: false,
                autoclose: true
            });

            $('#companyId').multiselect({
                enableFiltering: true,
                includeSelectAllOption: true,
                selectAllText: '全部',
                selectAllJustVisible: true,
                buttonWidth: '80%',
                nonSelectedText: '请选择所属公司',
                nSelectedText: ' - 已选择',
                numberDisplayed: 4,
                allSelectedText: '已选择全部'
            });
            $("#cancel").click(function () {
                $("#dialog_driver").modal("hide");
            });

            $("#save").click(function () {
                var driver_div = $("#driver_btn div");
                var driverStr = '';
                for (var j = 0; j < driver_div.length; j++) {
                    var d_div = driver_div[j];
                    driverStr += d_div.getAttribute("driverId");
                    if (j != driver_div.length - 1) {
                        driverStr += ",";
                    }
                }
                submit(driverStr);
            });

            function submit(driverStr) {
                if (save_submit) {
                    $.ajax({
                        type: "POST",
                        url: "${ctx}/driver/driverMoney",
                        data: {money: $("#money").val(), memo: $("#memo").val(), drivers: driverStr},
                        dataType: "json",
                        success: function (result) {
                        }
                    });
                    $.scojs_message("充值成功", $.scojs_message.TYPE_OK);
                    setTimeout(function () {
                        window.location.href = '${ctx}/driver/list';
                    }, 1000);
                }
                $("#dialog_driver").modal("hide");
                save_submit = false;
            }

            $(document).on('click', '.removedriver', function () {
                $(this).parent().parent().remove();
                $("#number").val($("#number").val() - 1);
                if ($("#number").val() == 0) {
                    $("#dialog_driver").modal("hide");
                }
            });


            $("#submit_button").click(function () {
                save_submit = true;

                if ($("#money").val() == null || $("#money").val() == '') {
                    $.scojs_message("请输入充值或扣费金额", $.scojs_message.TYPE_ERROR);
                    return false;
                }

                var reg = /^(-?\d+)(.[0-9]{0,2})?$/;
                if (!reg.test($("#money").val())) {
                    $.scojs_message('无效的金额！', $.scojs_message.TYPE_ERROR);
                    return false;
                }

                if ($("#money").val() > 1000000) {
                    $.scojs_message('金额过大！', $.scojs_message.TYPE_ERROR);
                    return false;
                }

                if ($("#memo").val() == null || $("#memo").val() == '' || $("#memo").val().trim() == '') {
                    $.scojs_message("请输入充值说明", $.scojs_message.TYPE_ERROR);
                    return false;
                }


                var companyIdsStr = '';
                if (null != $("#companyId").val()) {
                    companyIdsStr = $("#companyId").val().join(",");
                }

                var freezes = document.getElementsByName('freeze');
                var freezeStr;
                if (freezes[0].checked) {
                    freezeStr = true;
                } else {
                    freezeStr = null;
                }

                var types = []
                var typeStr = '';
                $("input[name=type]:checked").each(function (index, element) {
                    types.push($(element).val());
                });
                if (null != types && types.length > 0) {
                    typeStr = types.join(",");
                }

                var statusAll = [];
                var statusStr = '';
                $("input[name=status]:checked").each(function (index, element) {
                    statusAll.push($(element).val());
                });
                if (null != statusAll && statusAll.length > 0) {
                    statusStr = statusAll.join(",");
                }

                var jobTypeAll = [];
                var jobTypeStr = '';
                $("input[name=jobType]:checked").each(function (index, element) {
                    jobTypeAll.push($(element).val());
                });
                if (null != jobTypeAll && jobTypeAll.length > 0) {
                    jobTypeStr = jobTypeAll.join(",");
                }

                $.ajax({
                    type: "GET",
                    url: "${ctx}/driver/queryDrivers",
                    data: {
                        name: $("#name").val(),
                        phone: $("#phone").val(),
                        username: $("#username").val(),
                        virtual: $("#virtual").val(),
                        startTime: $("#startTime").val(),
                        endTime: $("#endTime").val(),
                        companyId: companyIdsStr,
                        type: typeStr,
                        freeze: freezeStr,
                        status: statusStr,
                        jobType: jobTypeStr
                    },
                    dataType: "json",
                    success: function (data) {
                        if (data.count > 0) {
                            $("#number").val(data.count);
                            var btnhtml = "";
                            for (var i = 0; i < data.driverList.length; i++) {
                                var driver = data.driverList[i];
                                btnhtml += "<div class='col-xs-3' style='margin-top:20px;' driverId='" + driver.id + "' ><span class='label label-info' style='font-size:15px;'>" + driver.realname + "&ensp;<span class='glyphicon glyphicon-remove removedriver' style='color:red;'></span></span></div></div>";
                            }
                            $("#driver_btn").html('');
                            $("#driver_btn").append(btnhtml);

                            $("#dialog_driver").modal();

                        } else {
                            $.scojs_message("未筛选出服务人员,请重新筛选", $.scojs_message.TYPE_ERROR);
                        }
                    }
                });
            });
        });
    </script>
</@override>
<@extends name="../layout.ftl"/>
